<template>
  <a-form :model="formState" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-form-item label="Activity name">
      <a-input v-model:value="formState.name" />
    </a-form-item>
    <a-form-item label="Activity zone">
      <a-select v-model:value="formState.region" placeholder="please select your zone">
        <a-select-option value="shanghai">Zone one</a-select-option>
        <a-select-option value="beijing">Zone two</a-select-option>
      </a-select>
    </a-form-item>
    <a-form-item label="Activity time">
      <a-range-picker :show-time="{ format: 'HH:mm:ss', defaultValue: formState.defaultTime }" format="YYYY-MM-DD HH:mm:ss" style="width:100%" @change="onChange" />
    </a-form-item>
    <a-form-item label="Instant delivery">
      <a-switch v-model:checked="formState.delivery" />
    </a-form-item>
    <a-form-item label="Activity type">
      <a-checkbox-group v-model:value="formState.type">
        <a-checkbox value="1" name="type">Online</a-checkbox>
        <a-checkbox value="2" name="type">Promotion</a-checkbox>
        <a-checkbox value="3" name="type">Offline</a-checkbox>
      </a-checkbox-group>
    </a-form-item>
    <a-form-item label="Resources">
      <a-radio-group v-model:value="formState.resource">
        <a-radio value="1">Sponsor</a-radio>
        <a-radio value="2">Venue</a-radio>
      </a-radio-group>
    </a-form-item>
    <a-form-item label="Activity form">
      <a-textarea v-model:value="formState.desc" auto-size />
    </a-form-item>
    <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button type="primary" @click="onSubmit">Create</a-button>
      <a-button style="margin-left: 10px" @click="handleCancel">Cancel</a-button>
      <a-button type="danger" @click="goCollapse">折叠面板</a-button>
    </a-form-item>
  </a-form>
</template>
<script lang="ts">
import moment, { Moment } from "moment";
import { defineComponent, onMounted, reactive } from "vue";
import { useStore } from "vuex";
import { getRealName } from "@/filters/index";
import { useRouter } from "vue-router";

interface FormState {
  name: string;
  region: string | undefined;
  date1: string[];
  delivery: boolean;
  type: string[];
  resource: string;
  desc: string;
  defaultTime: Moment[];
}
export default defineComponent({
  setup() {
    const store = useStore();
    const router = useRouter();
    const formState = reactive<FormState>({
      name: "",
      region: undefined,
      date1: [],
      delivery: false,
      type: [],
      resource: "",
      desc: "",
      defaultTime: [moment("00:00:00", "HH:mm:ss"), moment("23:59:59", "HH:mm:ss")],
    });

    const onSubmit = () => {
      console.log("submit!", formState);
    };

    const handleCancel = async () => {
      await store.dispatch("handleSetCount");
      console.log(store.getters.getCount);
    };

    const onChange = (value: Moment[], dateString: string[]) => {
      formState.date1 = dateString;
      console.log(formState.date1);
    };

    const goCollapse = () => {
      router.push("/form/collapse/123");
    };
    return {
      labelCol: { span: 2 },
      wrapperCol: { span: 8 },
      formState,
      onSubmit,
      onChange,
      getRealName,
      handleCancel,
      goCollapse,
    };
  },
});
</script>
